package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.adapter.TaxSearchAdapter;
import com.banshuibao.bsb_android.http.HttpResponse;
import com.banshuibao.bsb_android.http.HttpUtil;
import com.banshuibao.bsb_android.model.TaxMenuModel;

/**
 * Created by zyh on 2018/5/29.
 */

public class TaxSearchActivity extends BaseActivity {

    private RecyclerView recyclerView;

    private TaxSearchAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acitvity_tax_search);

        initView();
    }

    private void initView() {
        setTitleText("税率速查");
        recyclerView = findViewById(R.id.recyclerView);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
        recyclerView.setLayoutManager(gridLayoutManager);
        adapter = new TaxSearchAdapter(this);
        recyclerView.setAdapter(adapter);

        getData();
    }

    private void getData() {
        TaxMenuModel.Body body = new TaxMenuModel.Body();
        body.setSinceId(0);
        body.setMaxId(1000);
        HttpUtil.doPost(Constants.Url.TAX_RATE_LIST, body, new HttpResponse(context, TaxMenuModel.class) {
            @Override
            public void onResult(Object obj) {
                TaxMenuModel data = (TaxMenuModel) obj;
                if (adapter != null)
                    adapter.addData(data.getData());
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (adapter != null) {
            adapter.clear();
            adapter = null;
        }
    }
}
